package com.hermit.alaskagulfknife4j.controller;

import com.hermit.alaskagulfknife4j.entity.ResultBO;
import com.hermit.alaskagulfknife4j.entity.User;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author hermit
 * @data 2021/6/16
 */
@RequestMapping("/test")
@RestController
public class TestController {

    /**
     * 日志对象
     */
    private static final Logger logger = LoggerFactory.getLogger(TestController.class);

    @ApiOperation(value = "用户登录测试接口")
    @PostMapping("login")
    public ResultBO<User> login(@RequestBody User user, HttpServletRequest request, HttpServletResponse response) {
        ResultBO resultBO = new ResultBO();
        resultBO.setCode(666);
        resultBO.setSucceed(true);
        resultBO.setMsg("用户登录测试接口返回数据");
        return resultBO;
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "用户名称", dataType = "String", paramType = "String", example = "刘德华", required = true),
            @ApiImplicitParam(name = "message", value = "描述信息", dataType = "String", paramType = "String", example = "歌手", required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "接口返回成功状态"),
            @ApiResponse(code = 500, message = "接口返回失败状态"),
            @ApiResponse(code = 520, message = "接口返回神经状态")
    })
    @ApiOperation(value = "查询测试接口", notes = "这是一个查询测试接口的描述")
    @GetMapping("get-user/{name}/{message}")
    public ResultBO<User> getUser(@PathVariable String name, @PathVariable String message, HttpServletRequest request, HttpServletResponse response) {
        ResultBO resultBO = new ResultBO();
        resultBO.setCode(520);
        resultBO.setSucceed(true);
        resultBO.setMsg("查询测试接口");
        return resultBO;
    }

    @ApiOperation(value = "保存测试接口", notes = "这是一个保存用户信息的测试接口描述")
    @PostMapping("save-user")
    public ResultBO<User> saveUser(@RequestBody User user) {
        user.setName("name");
        user.setId(0);
        user.setUsername("username");
        user.setPassword("password");
        user.setComment("comment");
        user.setAddress("address");
        user.setSex("sex");
        user.setDeleteFlag(0);
        ResultBO result = new ResultBO();
        result.setContent(user);
        result.setMsg("SUCCESS");
        return result;
    }
}
